package org.kia.data.model;

import java.io.IOException;

import android.os.Parcel;
import com.github.droidfu.cachefu.CachedModel;
import com.github.droidfu.cachefu.ModelCache;
import com.google.gson.annotations.SerializedName;

public class AccessibilityItem extends CachedModel{
	//////////////////////////////////////////////
	// Members
	//////////////////////////////////////////////
	
	protected String mCachedId;
	
	@SerializedName("isAvailable")
	protected Boolean mIsAvailable;
	
	@SerializedName("name")
	protected String mName;
	
	@SerializedName("image")
	protected String mImage;


	//////////////////////////////////////////////
	// Constructors
	//////////////////////////////////////////////
	
	/**
	 * Constructs a new Category Model
	 */
	public AccessibilityItem() {
		
	}
	
	/**
	 * Constructs a new Category Model with given fields
	 * 
	 * @param id
	 * @param name
	 * @param image
	 */
	public AccessibilityItem(String id, String name, String image, Boolean isAccessible) {
		super();
		setModelId(id);
		this.mName = name;
		this.mImage = image;
		this.mIsAvailable = isAccessible;
	}
	
	/**
     * Constructor setting variables from parcel. Same as using a blank constructor and calling readFromParcel.
     *
     * @param source Parcel to be read from.
     * @throws java.io.IOException
     */
    public AccessibilityItem(Parcel source) throws IOException {
        super(source);
    }
	
	
    //////////////////////////////////////////////
	// Getters & Setters
	//////////////////////////////////////////////

    public String getId() {
    	return mCachedId;
    }
    
    public void setId(String id) {
    	mCachedId = id;
    }
    
    public void setModelId(String id) {
    	super.setId(id);
    }
    
    public String getModelId() {
    	return super.getId();
    }
    
	public String getName() {
		return mName;
	}

	public void setName(String name) {
		this.mName = name;
	}

	public String getImage() {
		return mImage;
	}

	public void setImage(String image) {
		this.mImage = image;
	}
	
/*
	@Override
	public String createKey(String arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean reloadFromCachedModel(ModelCache arg0, CachedModel arg1) {
		// TODO Auto-generated method stub
		return false;
	}
	
*/

//////////////////////////////////////////////
// Parcel
//////////////////////////////////////////////

/**
 * Creator object used for parceling
 */
public static final Creator<AccessibilityItem> CREATOR = new Creator<AccessibilityItem>() {

    public AccessibilityItem createFromParcel(Parcel source) {
        try {
            return new AccessibilityItem(source);
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

    public AccessibilityItem[] newArray(int size) {
        return new AccessibilityItem[size];
    }
};

//////////////////////////////////////////////
// Overrides
//////////////////////////////////////////////

@Override
public boolean reloadFromCachedModel(ModelCache modelCache, CachedModel cachedModel) {
	AccessibilityItem cachedObject = (AccessibilityItem) cachedModel;
    mCachedId = cachedObject.mCachedId;
    mIsAvailable = cachedObject.mIsAvailable;
    mName = cachedObject.mName;
    mImage = cachedObject.mImage;
    return false;
}

@Override
public void readFromParcel(Parcel source) throws IOException {
    super.readFromParcel(source);
    mCachedId = source.readString();
    mIsAvailable = source.readInt()==1;
    mName = source.readString();
    mImage = source.readString();
}

@Override
public void writeToParcel(Parcel dest, int flags) {
    super.writeToParcel(dest, flags);
    dest.writeString(mCachedId);
    dest.writeInt(mIsAvailable? 1 : 0);
    dest.writeString(mName);
    dest.writeString(mImage);
}

@Override
public String getKey() {
    if (mCachedId == null) {
        return null;
    } else {
        return createKey(mCachedId);
    }
}

@Override
public String createKey(String id) {
    return id;
}

}